dojo.declare("MCustomerOrderHistoryPg", wm.Page, {
    start: function() {
        this.loadHistory();
    },
    "preferredDevice": "phone",

    list1OrderIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {

        var comment = "";
        var vendorComment = "";
        if (rowObj.comments && rowObj.comments !== null) {
            comment = rowObj.comments;
        }
        if (rowObj.vendor_comment && rowObj.vendor_comment !== null) {
            vendorComment = rowObj.vendor_comment;
        }
        var display = " <div style='font-weight: normal;'>Order#:" + rowObj.orderId + ", " + // "</div>" + 
        // "<div class='MobileRow'>" +
        wm.List.prototype.dateFormatter({
            "formatLength": "medium",
            "dateType": "date and time"
        }, null, null, null, rowObj.orderDt) + "</div>" + "<div style='display:block;font-weight: normal;'>Vendor: " + rowObj.customerByVendorId.name + ", Order Status: " + rowObj.status //"</div>"+
        // "<div style='display:block;font-weight: normal;'>Order Status :" + rowObj.status +
        // "</div>" 
        + "<div style='display:block;font-weight: normal;'>My Comments:" + comment + "</div>"


        + "<div style='display:block;font-weight: normal;'>Vendor Comments:" + vendorComment + "</div>"

        display = display + "  <div style='display:block;font-weight: normal;'>Price    :Rs " + rowObj.totalPrice + "  </div> "
        return display;
    },
    list1Select2: function(inSender, inItem) {
        // this.mbCustomerHistory.setShowing(true);
        //  this.labelOrderItemDetails.setShowing(true);
        //  this.labelOrderDetails.setShowing(false);
        wm.Page.getPage("MCustomerHomePg").vPageBack = "CUSTOMER_HISTORY";
    },

    list2OrderItemIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var display = "<div style='display:block;font-weight: normal;'> <b>" + rowObj.quantity + " " + rowObj.items.itemName + "  Price: Rs " + rowObj.price + "</b></div>";
        //"<div class='MobileRow'>Item Desc: " + rowObj.items.itemDesc +
        //  "</div>" + "<div style='display:block;font-weight: normal;'>Quantity:<b> " + rowObj.quantity + "</b> Price: Rs <b>" + rowObj.price + "</b></div>";
        // "</div>" + "<div class='MobileRow'>Price: " + rowObj.price + "</div>"
        if (rowObj.comments && rowObj.comments != null) {
            // display = display + " <div class='MobileRow'>Comments: " + rowObj.comments + "</div>"
        };


        var unit = rowObj.items.unit;

        if (!unit || unit === null) {
            unit = "";
        }
        display = " <div style='display:block;font-weight: normal;'> <b> &nbsp;&nbsp;";
        display = display + rowObj.items.itemName + "," + rowObj.price + "Rs (" + rowObj.quantity + " " + unit + " @" + rowObj.items.price + "Rs)";
        display = display + "</br> ";
        display = display + "</b></div> ";


        return display;
    },
    labelBackToResultsClick: function(inSender, inEvent) {
        this.labelBackToResults.setShowing(false);
        this.labelOrderItemDetails.setShowing(false);
        this.labelOrderDetails.setShowing(true);
        this.layerOrders.activate();

    },
    loadHistory: function() {
        var mainPage = wm.Page.getPage("MobileMainPg");

        this.lvMyOrders.filter.setValue("customerByCustomerId.customerId", mainPage.vUserId);
        this.lvMyOrders.update();

    },
    list1StatusFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var buttonText = '<img src ="resources/images/mobile/next_img.png" height="26px" />';
        return buttonText;
    },
    svClearHistoryError: function(inSender, inError) {

    },
    lvOrderItemsSuccess: function(inSender, inDeprecated) {
        var display = ""; //" <div style='display:block;font-weight: normal;'> <b>";
        for (var count = 0; count < this.lvOrderItems.getCount(); count++) {

            var vItem = this.lvOrderItems.getItem(count);
            var unit = vItem.data.items.data.unit;

            if (!unit || unit === null) {
                unit = "";
            }
            display = display + " <div style='display:block;font-weight: normal;'> <b> &nbsp;&nbsp;";
            display = display + vItem.data.items.data.itemName + "," + vItem.data.price + "Rs (" + vItem.data.quantity + " " + unit + " @" + vItem.data.items.data.price + "Rs)";
            display = display + "</br> ";
            display = display + "</b></div> ";
        }

        this.labelOrderDetailsList.setCaption(display);
    },






    _end: 0
});